package com.cgbl.cg.view

import android.content.Context
import android.text.TextUtils
import android.widget.EditText
import android.widget.ImageView
import android.widget.Switch
import android.widget.TextView
import androidx.appcompat.widget.SwitchCompat
import com.cgbl.cg.R
import com.lxj.xpopup.core.BottomPopupView
import com.robot.base.util.ToastUtils

class CreateFolderPop(context: Context) : BottomPopupView(context) {

    var listener: ((String, String, Boolean) -> Unit)? = null
    override fun getImplLayoutId(): Int {
        return R.layout.app_pop_create_folder
    }

    override fun initPopupContent() {
        super.initPopupContent()
        val folderNameEditText: EditText = findViewById(R.id.et_folder_name)
        val folderDescEditText: EditText = findViewById(R.id.et_folder_desc)
        val switchFolder: SwitchCompat = findViewById(R.id.switch_folder)
        val cancelBtn: TextView = findViewById(R.id.btn_cancel)
        val confirmBtn: TextView = findViewById(R.id.btn_confirm)
        val ivBack: ImageView = findViewById(R.id.iv_back)
        ivBack.setOnClickListener {
            dismiss()
        }

        confirmBtn.setOnClickListener {

            val name = folderNameEditText.text.toString()

            val desc = folderDescEditText.text.toString()

            val isOpen = switchFolder.isChecked

            if (TextUtils.isEmpty(name)) {
                ToastUtils.showShort("请输入文件夹名称!")
                return@setOnClickListener
            }

            if (TextUtils.isEmpty(name)) {
                ToastUtils.showShort("请输入文件夹描述!")
                return@setOnClickListener
            }

            listener?.invoke(name, desc, isOpen)
            dismiss()
        }

        cancelBtn.setOnClickListener { dismiss() }

    }

    fun setOnCreateFolderListener(listener: (String, String, Boolean) -> Unit) {
        this.listener = listener
    }

}